/* Copyright 2008 Bas van den Berg
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "AdminCommands.h"
#include "Session.h"
#include "Global.h"
#include "TaskQueue.h"
#include "Utils.h"

#include "SessionManager.h"
#include "Parser.h"
#include "World.h"
#include "Area.h"

#include "svnversion.h"

using namespace Chronos;
using namespace std;

void AreaListCommand::execute(Session& session) {
    Global<World>()->printAreas(session.write());
}


void RoomListCommand::execute(Session& session, const std::string& arg1) {
	int areaID = atoi(arg1.c_str());
    const Area* area = Global<World>()->findArea(areaID);
    if (area == 0) {
        session.write() << "unknown areaID\n";
        return;
    }
    session.write() << "Area: " << area->getName() << '\n';
    area->printRooms(session.write());
}


void ServerCommand::execute(Session& session) {
    session.write() << "Server status:\n"; 
    session.write() << "  svn(" << SVN_VERSION << "),  it is now " << Utils::getTime() << ", up " << Utils::toDurationString(Utils::getPulse()) << '\n';
    Global<SessionManager>()->printStatus(session.write());
    Global<SessionManager>()->getParser().printStatus(session.write());
    Global<TaskQueue>()->printStatus(session.write());
    Global<World>()->printStatus(session.write());
}


void KillsCommand::execute(Session& session) {
    session.write() << "Kill statistics:\n"; 
    Global<World>()->getKills().print(session.write());
}

